package com.ushine.web.template.test.client;

import com.ushine.web.template.test.constant.BorderConstant;
import com.ushine.web.template.test.constant.LengthConstant;
import com.ushine.web.template.test.constant.StringTypeEnum;
import com.ushine.web.template.test.utils.PasswordTestUtils;
import com.ushine.web.template.test.utils.StringTestUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: yls
 * @Date 2022/3/15 15:08
 * @Description: 测试客户端
 * @Version 1.0
 **/
@Component
public class StringClient {

    @Resource
    private StringTestUtils stringTestUtils;

    @Resource
    private PasswordTestUtils passwordTestUtils;

    /**
     * 功能描述:
     * 〈 穷举生成字符串〉
     *
     * @param minLength 最小长度
     * @param maxLength 最大长度
     * @return : java.util.List<java.lang.String>
     * @author : yls
     * @date : 2022/3/15 15:20
     */
    public Map<String, String> getStringData(Integer minLength, Integer maxLength) {
        Map<String, String> resultMap = new HashMap<>(9);
        // NULL对象
        resultMap.put(BorderConstant.NULL_VALUE, null);
        // 空字符串
        resultMap.put(BorderConstant.BLACK_VALUE, "");
        // 特殊符号
        int middleLength = minLength + maxLength / 2;
        String randomChinese = stringTestUtils.getRandomChinese(1);
        String random = passwordTestUtils.getRandom(middleLength, StringTypeEnum.SIGN);
        resultMap.put(BorderConstant.SPECIAL_SYMBOLS_VALUE, randomChinese + random);
        // 组合方式()
        String letterNumber = passwordTestUtils.getRandom(middleLength, StringTypeEnum.LETTER_CAPITAL_NUMBER);
        resultMap.put(BorderConstant.COMBINATION_VALUE, randomChinese + letterNumber);
        // 获取小于最小长度的值
        randomChinese = stringTestUtils.getRandomChinese(minLength - 1);
        resultMap.put(BorderConstant.LESS_THAN_MIN_VALUE, randomChinese);
        // 获取最小长度的值
        randomChinese = stringTestUtils.getRandomChinese(minLength);
        resultMap.put(BorderConstant.MIN_VALUE, randomChinese);
        // 生成中间值
        randomChinese = stringTestUtils.getRandomChinese(middleLength);
        resultMap.put(BorderConstant.NORMAL_VALUE, randomChinese);
        // 获取最大值的值
        randomChinese = stringTestUtils.getRandomChinese(maxLength);
        resultMap.put(BorderConstant.MAX_VALUE, randomChinese);
        // 获取大于最大值的值
        randomChinese = stringTestUtils.getRandomChinese(maxLength + 1);
        resultMap.put(BorderConstant.GREATER_THAN_MIN_VALUE, randomChinese);
        return resultMap;
    }

    /**
     * 功能描述:
     * 〈 获取字符串的随机值 〉
     *
     * @param minLength 最小长度
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @author : yls
     * @date : 2022/3/15 16:23
     */
    public Map<String, String> getStringDataByMin(  Integer minLength) {
        return getStringData( minLength, LengthConstant.STR_MAX_LENGTH);
    }

    /**
     * 功能描述:
     * 〈获取字符串的随机值〉
     *
     * @param maxLength 最大值
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @throws
     * @author : yls
     * @date : 2022/3/15 16:24
     */
    public Map<String, String> getStringDataByMax(Integer maxLength) {
        return getStringData(LengthConstant.STR_MIN_LENGTH, maxLength);
    }

    /**
     * 功能描述:
     * 〈获取字符串的随机值〉
     *
     * @return : java.util.Map<java.lang.String,java.lang.String>
     * @throws
     * @author : yls
     * @date : 2022/3/15 16:24
     */
    public Map<String, String> getStringData( ) {
        return getStringData(LengthConstant.STR_MIN_LENGTH, LengthConstant.STR_MAX_LENGTH);
    }

}
